/**
 * @author wangj881
 * @date 2025-01-09 17:01
 */
public class L141_3 {
    public static void main(String[] args) {

    }

    public class Solution {
        public boolean hasCycle(ListNode head) {

            ListNode slow = head;
            ListNode fast = head;

            while (fast != null && fast.next != null) {
                slow = slow.next;
                fast = fast.next.next;
                if (fast == slow) {
                    return true;
                }
            }
            return false;
        }
    }
}
